#include<iostream>
#include<algorithm>
using namespace std;
const int N = 330;
struct Node
{
	int a, b, c;
	int sum;
	int id;
}s[N];
int cmp(Node a, Node b)
{
	if (a.sum != b.sum) {
		return a.sum > b.sum;
	}
	else {
		if (a.a != b.a) {
			return a.a > b.a;
		}
		else {
			return a.id < b.id;
		}
	}
}
int main()
{
	int n;
	cin >> n;
	for (int i = 0; i < n; i++) {
		int a, b, c;
		cin >> a >> b >> c;
		int sum = a + b + c;
		s[i] = { a,b,c,sum,i + 1 };
	}
	sort(s, s + n, cmp);
	for (int i = 0; i < 5; i++) {
		cout << s[i].id << " " << s[i].sum << endl;
	}
	return 0;
}